package com.ams.thread.lesson3;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author： 乐哥聊编程(全平台同号)
 */
@Slf4j
public class Example12 {
    public static Object lock = new Object();
    public static void main(String[] args) {
        Thread threadA = new Thread(new ThreadA());
        Thread threadB = new Thread(new ThreadB(threadA));
        threadB.start();
        threadA.start();
    }

    static class ThreadA implements Runnable{

        @Override
        public void run() {
            for (int i=0;i<5;i++){
                log.info(String.valueOf(i));
                ThreadUtil.sleep(1000);
            }
        }
    }
    static class ThreadB implements Runnable{
        private Thread thread;
        public ThreadB(Thread thread){
            this.thread = thread;
        }
        @Override
        public void run() {
            try {
                thread.join();
                log.info("线程A已经执行完了 该我执行了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
